package com.jiyun.controller;

import com.jiyun.bean.User;
import com.jiyun.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@RestController
public class HelloController {
    @Autowired
    private UserService userService;

    @RequestMapping("/hello")
    public User hello(){
        User user = userService.getQueryByid(1l);
        return user;
    }

    @RequestMapping("/view")
    public ModelAndView getView(Model model){
        ModelAndView view = new ModelAndView();
        //User user = userService.getQueryByid(1l);
        view.addObject("msg","hello jiyun");

        List<User> list = new ArrayList<>();
        list.add(new User(1l,"张三","20"));
        list.add(new User(2l,"李四","30"));
        list.add(new User(3l,"王五","40"));

        model.addAttribute("list",list);
        view.setViewName("/view");
        return view;
    }




}
